package jjn.weekly;

/**
 * @author Jiang Jining
 * @since 2023-06-04 10:34
 */
public class LeetCode6424 {
    public int semiOrderedPermutation(int[] nums) {
        int max = nums.length, min = 1;
        int maxIndex = 0, minIndex = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == max) {
                maxIndex = i;
            }
            if (nums[i] == min) {
                minIndex = i;
            }
        }
        if (minIndex < maxIndex) {
            return nums.length - 1 - maxIndex + minIndex;
        }
        return nums.length - 1 - maxIndex + minIndex - 1;
    }
    
}
